package com.ice.body.log.service.impl;

import com.ice.base.dao.BaseDao;
import com.ice.base.model.SysLoginModel;
import com.ice.base.service.impl.BaseServiceImpl;
import com.ice.base.util.BaseUtil;
import com.ice.body.business.model.ReagentStock;
import com.ice.body.business.model.RecordLab;
import com.ice.body.business.service.ReagentStockService;
import com.ice.body.business.service.RecordLabService;
import com.ice.body.log.dao.LogDestroyMapper;
import com.ice.body.log.model.LogDestroy;
import com.ice.body.log.service.LogDestroyService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created with GuoYanBin.
 * Description:试剂销毁 serviceImpl
 * Date: 2022-11-15
 * Time: 02:00
 */
@Service
public class LogDestroyServiceImpl extends BaseServiceImpl<LogDestroy> implements LogDestroyService {
    @Resource 
    private LogDestroyMapper logDestroyMapper;
    @Resource
    private RecordLabService reagentRecordService;
    @Resource
    private ReagentStockService reagentStockService;

    @Override
    public BaseDao<LogDestroy> getBaseDao() {
        return logDestroyMapper;
    }

    /**
     * stock表 状态改为9 销毁
     * @param model
     * @return
     */
    @Transactional
    @Override
    public Integer destroy(LogDestroy model) {
        SysLoginModel user = BaseUtil.getCurrLoginModel();
        ReagentStock reagentEpc = reagentStockService.getByEpcCode(model.getEpcCode());//根据epc编号查询试剂信息
        //添加记录
        RecordLab rrModel = BaseUtil.getRecordModel(1);
        rrModel.setEpcCode(model.getEpcCode());
      //  rrModel.setUserId(user.getId());
        rrModel.setUserName(user.getUserName());
        rrModel.setCName(reagentEpc.getCName());
        reagentRecordService.insert(rrModel);
        //修改stock表
        reagentStockService.destroy(model);

        model.setCreateTime(new Date());
        return logDestroyMapper.insert(model);
    }
}
